perm filename HAX.SAI[SAI,LES] blob sn#855064 filedate 1988-03-27 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00005 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	entry ask,look,lookout,lookon,look1,ent,entout,enton,left,center,prep0
C00004 00003	string proc look(string file)  begin
C00007 00004	boolean proc ENT(string file)  begin
C00008 00005	define blanks=["                   "]
C00009 ENDMK
C⊗;
entry ask,look,lookout,lookon,look1,ent,entout,enton,left,center,prep0;
begin "HAX"

require "macro.sai" source_file;
redefine proc=[simple internal procedure];

internal integer inch,ouch,brk,eof,inlf,inff,inprt,inwht; ! input/output globals;

string proc myreal(real r);	begin		! use this in PRINT;
    integer hi,lo;
    getformat(hi,lo);
    return(if lo then cvf(r) else cvs(r+0.5))
    end;

external integer array gogtab[1:300];
proc PREP0;  begin 				! initialize things;
    setbreak(inlf←getbreak,LF,CR,"INS");
    setbreak(inff←getbreak,FF,NULL,"INS");
    setbreak(inprt←getbreak," "&tab&lf&ff,cr,"is"); ! get printing characters;
    setbreak(inwht←getbreak," "&tab&lf&ff&cr,"","xr"); ! get nonprinting chars;
    require "sys:gogtab.def" source_file;
    gogtab[$$frel]←location(myreal);		! change print(real);
    end;

string proc ask(string s);  begin outstr(s);  return(inchwl)  end;

proc OOPS(string mess); begin say(↓&mess&↓); call(0,"RESET"); exit; end;

string proc look(string file);  begin
! does an open and lookup on a text file and delivers the first line,
ignoring the TV/E directory,if any;
    string lin; boolean fl;
    open(inch←getchan,"DSK",1,19,0,400,brk,eof);
    lookup(inch,file,fl);
    if fl then begin release(inch); return(del) end;
    lin←inlines;
    if equ(lin[1 to 9],"COMMENT ⊗") then begin "flush directory"
	do informs until brk=ff;
	return(inlines);
	end;
    return(lin)
    end "LOOK";
string proc lookout(string file);	begin	string ss;
	if ¬equ(ss←look(file),del) then return(ss) else oops(file&" not found"&↓);
	return(ss)
	end;
string proc lookon(string file);	begin   string ss;
	while equ(ss←look(file),del) do file←ask(FILE&" not found
File=");
	return(ss)
	end;
string proc look1(string file);  begin
! does an open and lookup on a text file and skips any directory page,
and delivers the first word;
    string lin; boolean fl;
    open(inch←getchan,"DSK",1,19,0,400,brk,eof);
    lookup(inch,file,fl);
    if fl then begin
	print(file," not found"&↓);
	release(inch);
	return(null)
    end;
    if equ(lin←inprints,"COMMENT") then begin
	do informs until brk=ff;
	lin←null;
    end;
    if ln(lin)=0 then begin inwhiter; lin←inprints; end;
    return(lin)
end "LOOK1";

boolean proc ENT(string file);  begin
! does an OPEN and ENTER on a text file and returns TRUE if OK & MODE=0;
    boolean fl;
    open(ouch←getchan,"DSK",1,0,19,0,0,0);
    enter(ouch,file,fl);
    if fl then release(ouch);
    return(¬fl)
    end "ENT";
proc entout(string file);
    if ¬ent(file) then oops(file&" cannot be written");
proc enton(string file);
    while ¬ent(file) do file←ask(file&" cannot be written
File=");

define blanks=["                   "];
string proc center(integer s; string txt);  return(if ln(txt)≥s then txt[1 to s]
    else blanks[1 to (s-ln(txt))/2]&txt&blanks[1 to (s-ln(txt)+1)/2]);
string proc left(integer s; string txt); return(if ln(txt)≥s then txt[1 to s]
    else txt&blanks[1 to s-ln(txt)]);
end